<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
		<link href="../css/style.css" rel="stylesheet" />
		<!--common---start-->
		<script src="../js/angular/angular.min.js"></script>
		<script src="../js/angular/angular-resource.js"></script>
		<script src="../js/angular/common.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/common.js"></script>
		<!--common---end-->
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.mui-bar~.mui-content .mui-fullscreen {
				top: 44px;
				height: auto;
			}
			.mui-pull-top-tips {
				position: absolute;
				top: -20px;
				left: 50%;
				margin-left: -25px;
				width: 40px;
				height: 40px;
				border-radius: 100%;
				z-index: 1;
			}
			.mui-bar~.mui-pull-top-tips {
				top: 24px;
			}
			.mui-pull-top-wrapper {
				width: 42px;
				height: 42px;
				display: block;
				text-align: center;
				background-color: #efeff4;
				border: 1px solid #ddd;
				border-radius: 25px;
				background-clip: padding-box;
				box-shadow: 0 4px 10px #bbb;
				overflow: hidden;
			}
			.mui-pull-top-tips.mui-transitioning {
				-webkit-transition-duration: 200ms;
				transition-duration: 200ms;
			}
			.mui-pull-top-tips .mui-pull-loading {
				/*-webkit-backface-visibility: hidden;
				-webkit-transition-duration: 400ms;
				transition-duration: 400ms;*/
				
				margin: 0;
			}
			.mui-pull-top-wrapper .mui-icon,
			.mui-pull-top-wrapper .mui-spinner {
				margin-top: 7px;
			}
			.mui-pull-top-wrapper .mui-icon.mui-reverse {
				/*-webkit-transform: rotate(180deg) translateZ(0);*/
			}
			.mui-pull-bottom-tips {
				text-align: center;
				background-color: #efeff4;
				font-size: 15px;
				line-height: 40px;
				color: #777;
			}
			.mui-pull-top-canvas {
				overflow: hidden;
				background-color: #fafafa;
				border-radius: 40px;
				box-shadow: 0 4px 10px #bbb;
				width: 40px;
				height: 40px;
				margin: 0 auto;
			}
			.mui-pull-top-canvas canvas {
				width: 40px;
			}
			.mui-slider-indicator.mui-segmented-control {
				background-color: #efeff4;
			}
		</style>
	</head>

	<body ng-app="mainApp" ng-controller="goodsCtrl">
		<header class="mui-bar mui-bar-nav mui-bar-in">
			<h1 class="mui-title ">
				<img ng-src="{{baseUrl}}/dapi/download/getImageIO?imgUrl={{agent.iconUrl}}" width="80" height="25" >
			</h1>
			<div class="mui-input-row mui-search "style="margin-left: 100px;">
				<input type="search" class="mui-input-clear" placeholder="" id="searchTitle">
			</div>
			<a class="mui-icon mui-pull-right right" ng-click="searchBtnClick()">搜索</a>
		</header>
		<div class="mui-content">
			<div class="notice_wrap">
				<div class="notice">
					<div class="notice_tit"><i class="mui-icon mui-icon-extra mui-icon-extra-notice"></i>公告通知：</div>
					<div id="wrapper" class="wrapper">
						<div class="inner">
							<p class="txt" id="noticeText">！</p>
						</div>
					</div>

				</div>
			</div>
			<div id="slider" class="mui-slider mui-fullscreen">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a class="mui-control-item " ng-class="{'mui-active':initIndex==$index}"  href="#{{item.id}}" ng-repeat="item in topList">
							{{item.typeName}}
						</a>
					</div>
				</div>
				<div class="mui-slider-group"style="height: 100px;">
					<div id="{{item.id}}"  ng-repeat="item in topList"  class="mui-slider-item mui-control-content " ng-class="{'mui-active':initIndex==$index}" on-finish-render-filters>
						<div  class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<div class="mui-content pro_con">
									<ul class="mui-table-view mui-grid-view">
										<li class="mui-table-view-cell mui-media mui-col-xs-6" ng-repeat="goods in item.goodsList"  ng-click="goodsDetailPage(goods.id)" >
											<a href="#">
												<img ng-if="goods.iconUrl!=undefined&&goods.iconUrl!=''" class="mui-media-object" ng-src="{{baseUrl}}/dapi/download/getImageIO?imgUrl={{goods.iconUrl}}"></img>
												<img ng-if="goods.iconUrl==undefined||goods.iconUrl==''" class="mui-media-object" ng-src="../images/goodsDefault.gif"></img>
												<div class="mui-media-body">{{goods.title}}</div>
											</a>
										</li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="../js/service/goodsService.js"></script>
		<script src="../js/service/agentService.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/mui.pullToRefresh.js"></script>
		<script src="../js/mui.pullToRefresh.material.js"></script>
		<script>
			mainApp.controller('goodsCtrl', function($scope, $http,goodsService,agentService) {
				$scope.baseUrl=baseUrl;
				$scope.pageSize=10;
				mui.init();
				(function($) {
					//阻尼系数
					var deceleration = mui.os.ios?0.003:0.0009;
					$('.mui-scroll-wrapper').scroll({
						bounce: false,
						indicators: true, //是否显示滚动条
						deceleration:deceleration
					});
					$.ready(function() {
						//循环初始化所有下拉刷新，上拉加载。
						
						$scope.topList=[{'id':'item1mobile',"title":"推荐 "}];//初始化数据启动滑屏
						
						goodsService.getGoogsListInit("qzj",$scope.pageSize,{},function(data){
							$scope.topList=data.data;
						},function(){})
						
						
						$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
							$.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) {
								$(pullRefreshEl).pullToRefresh({
									up: {
										callback: function() {
											var self = this;
											setTimeout(function() {
												var ul = self.element.querySelector('.mui-table-view');
												//ul.appendChild(createFragment(ul, index, 5));
												getList(index);
												self.endPullUpToRefresh();
											}, 1000);
										}
									}
								});
							});
							$('.mui-scroll-wrapper').scroll({
								bounce: false,
								indicators: true, //是否显示滚动条
								deceleration:deceleration
							});
						});
						$scope.initIndex=0;
						var startNum=0;
						var getList=function(index){
							//alert($scope.topList[index].goodsList.length);
							var startNum=$scope.topList[index].goodsList.length;
							var styleId=$scope.topList[index].id;
							$scope.searchTitle=document.getElementById("searchTitle").value;
							$scope.dzParam={"checkStatus":'1',"title":$scope.searchTitle};
							$scope.dzParam.gstyle=styleId;
							//请求商品列表数据
							goodsService.getGoogsListSH(startNum,$scope.pageSize,$scope.dzParam,function(data){
								if($scope.startNum==0){
									$scope.topList[index].goodsList=data.data.list;
								}else{
									angular.forEach(data.data.list, function(goods) {
										$scope.topList[index].goodsList.push(goods);
									});
								}
							},error) ;
						};
						
						
						$scope.goodsDetailPage=function(goodsId){
							mui.openWindow({
								url:"goodsDetails.html",
								id:'goodsDetails.html',
							    extras:{
							        goodsId:goodsId
							    },
							    styles: {
									popGesture:"close"	
								}
							});
						}
						agentService.getAgentByUser(function(data){
							$scope.agent=data.data;
						},error);
						goodsService.getNotic(function(data){
							document.getElementById('noticeText').innerHTML=data.data.title;
						},error);
						
						var wrapper = document.getElementById('wrapper');
						var inner = wrapper.getElementsByTagName('div')[0];
						var p = document.getElementsByTagName('p')[0];
						var p_w = p.offsetWidth;
						var wrapper_w = wrapper.offsetWidth;
						window.onload = function fun() {
							if(wrapper_w > p_w) {
								return false;
							}
							inner.innerHTML += inner.innerHTML;
							setInterval(fun1, 30);
						};
			
						function fun1() {
							if(p_w > wrapper.scrollLeft) {
								wrapper.scrollLeft++;
								
							} else {
								setTimeout(fun2, 1);
							}
						}
			
						function fun2() {
							wrapper.scrollLeft = 0;
							fun1();
						}
					
						
						
					});
				})(mui);
			});
			
		</script>
	</body>

</html>